var vm = new Vue({
    el: '#contentContainer',
    data: {
        form: {
            oldPass: '',
            password: '',
            password2: ''
        },
        rules: {
            oldPass: [
                {required: true, message: '请输入原密码', trigger: 'blur'},
                {min: 0, max: 50, message: '长度不能超过50个字符', trigger: 'blur'}
            ],
            password: [
                {required: true, message: '请输入新密码', trigger: 'blur'},
                {min: 0, max: 50, message: '长度不能超过50个字符', trigger: 'blur'}
            ],
            password2: [
                {required: true, message: '请输入新密码', trigger: 'blur'},
                {min: 0, max: 50, message: '长度不能超过50个字符', trigger: 'blur'}
            ]
        }
    },
    methods: {
        submitForm: function (formName) {
            var $this = this;

            $this.$refs[formName].validate(function (valid) {
                if (!valid)
                    return false;

                if ($this.form.password != $this.form.password2) {
                    $this.$notify.error({
                        title: '错误',
                        message: "两次输入的密码不一致",
                        offset: $("#main", window.parent.document).height() - 120,
                        duration: 3000
                    });

                    return false;
                }

                Common.postJson('/changePass', $this.form,
                    function (response) {
                        if (!response)
                            return;

                        //保存成功
                        if (response.status == 200 && response.result.success)
                            parent.window.location.href = '/';
                        else {
                            var errMsg = response.status == 200 ? response.result.errMsg : response.msg;

                            $this.$notify.error({
                                title: '错误',
                                message: errMsg,
                                offset: $("#main", window.parent.document).height() - 120,
                                duration: 0
                            });
                        }
                    });
            });
        },
        resetForm: function (formName) {
            this.$refs[formName].resetFields();
        }
    }
});